/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package muhnes.sizoo.controlador;


import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import muhnes.sizoo.dal.PhylumDao;
import muhnes.sizoo.dal.PhylumDaoImpl;
import muhnes.sizoo.modelo.Phylum;
/**
 *
 * @author Ricardo Orellana
 */
@ManagedBean(name = "phylumBean")
@ViewScoped
public class PhylumBean implements Serializable {
    
    private Phylum phylum;
    private List<Phylum> listaPhylum;
    
    public PhylumBean() {
        PhylumDao dao = new PhylumDaoImpl();
        phylum = new Phylum();
        listaPhylum = dao.buscarTodos();
    }

    public Phylum getPhylum() {
        return phylum;
    }

    public void setPhylum(Phylum phylum) {
        this.phylum = phylum;
    }
    
    public List<Phylum> getListaPhylum() {
        if( listaPhylum == null ) {
            PhylumDao dao = new PhylumDaoImpl();
            listaPhylum = dao.buscarTodos();
        }
        return listaPhylum;
    }

    public void setListaPhylum(List<Phylum> listaPhylum) {
        this.listaPhylum = listaPhylum;
    }   
    
     public void prepararAdicion( ActionEvent event  ){
        phylum = new Phylum();
    }
    
    public void prepararModificacion( Phylum phylum ){
        this.phylum = phylum;
    }
    
    public void prepararEliminacion( Phylum phylum ){
        this.phylum = phylum;
    }
    
    public void agregarPhylum( ActionEvent event ){
        PhylumDaoImpl dao = new PhylumDaoImpl();
        phylum.setHabilitado( Boolean.TRUE );
        dao.guardar( phylum );
        recrearLista();
    }
    
     public void actualizarPhylum( ActionEvent event ){
        PhylumDaoImpl dao = new PhylumDaoImpl();
        dao.actualizar( phylum );
        recrearLista();
    }
    
    public void eliminarPhylum( ActionEvent event ){
        PhylumDaoImpl dao = new PhylumDaoImpl();
        dao.eliminar( phylum );
        recrearLista();
    }
    
    void recrearLista() {
        listaPhylum = null;
    }
    
}
